<?php

class Kd_Html_Grid_Cell_Image extends Kd_Html_Grid_Cell_Base {

	private $_imageUrl = '';
	private $_emptyImageUrl = '';
	private $_imageWidth = NULL;
	private $_imageHeight = NULL;

	public function __construct(){
		parent::__construct();
		$this->templateName = 'grid/cell/image';
	}

	public function getEmptyImageUrl(){
		return $this->_emptyImageUrl;
	}
	public function setEmptyImageUrl($value){
		$this->_emptyImageUrl = $value;
		return $this;
	}

	public function getImageUrl(){
		return $this->_imageUrl;
	}
	public function setImageUrl($value){
		$this->_imageUrl = $value;
		return $this;
	}

	public function getImageWidth(){
		return $this->_imageWidth;
	}
	public function setImageWidth($value){
		$this->_imageWidth = $value;
		return $this;
	}

	public function getImageHeight(){
		return $this->_imageHeight;
	}
	public function setImageHeight($value){
		$this->_imageHeight = $value;
		return $this;
	}

	public function getCellImageUrl(){
		$result = Kd_Util_String::format($this->getImageUrl(), $this->getGrid()->getCurrentRow());
		if(empty($result)){
			$result = $this->getEmptyImageUrl();
		}
		return $result;
	}

	protected function render(){
		$result = "<img";
		if(!is_null($this->_imageWidth)){
			$result .= ' width="'.$this->getImageWidth().'"';
		}
		if(!is_null($this->_imageHeight)){
			$result .= ' height="'.$this->getImageHeight().'"';
		}
		return $result .' src="'.$this->getCellImageUrl().'"/>';
	}
}